<?php include("src/addRequest_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />
<title>Add Request :: First United Services LLC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>
<link rel="stylesheet" href="js/fancybox/fancy.css" type="text/css" media="screen">
<script type="text/javascript" src="js/fancybox/jquery.fancybox-1.0.0.js"></script>
<script language="javascript" type="text/javascript">
	
	$(document).ready(function() {
		$(".fancyto").fancybox({
				 'zoomSpeedIn': 700, //Provoca el efecto al abrirse
				 'zoomSpeedOut': 500, //Provoca el efecto al cerrarse.
				 'frameWidth': 450, // Ancho del reproductor.
				 'frameHeight': 150, // Alto del reproductor
				 'overlayShow': true, // Parámetro que sirve para definir si se muestra o no el fondo oscuro.
				 'overlayOpacity': 0.4 //Determina el nivel de opacidad del fondo.
		 });
		 
		 $(".fancytoContact").fancybox({
				 'zoomSpeedIn': 700, //Provoca el efecto al abrirse
				 'zoomSpeedOut': 500, //Provoca el efecto al cerrarse.
				 'frameWidth': 450, // Ancho del reproductor.
				 'frameHeight': 160, // Alto del reproductor
				 'overlayShow': true, // Parámetro que sirve para definir si se muestra o no el fondo oscuro.
				 'overlayOpacity': 0.4 //Determina el nivel de opacidad del fondo.
		 });
	});
	
	function validate(){
		var msg = '';
				
		var cli_code = document.getElementById("cli_code").value;     
 		var case_code = document.getElementById("case_code").value;
		var ban_code = document.getElementById("ban_code").value;
		var baco_code = document.getElementById("baco_code").value;
		
		if(cli_code == '') 
			msg='- Please select a client. <br />';
		else{
			if(case_code == '') 
				msg='- Please select a case number.<br />';
		}
		
		if(ban_code == '') 
			msg= msg+'- Please select a Bank. <br />';
		else{
			if(baco_code == '') 
				msg= msg+'- Please select a phone of the bank. \n';	
		}
		
		if(msg==''){
			document.getElementById('form').submit();
			return true;
		}
		else{
			coolMessage("alert", msg);
			return false;
		}		
	}
	
	function chargeCases(cli_code){
		jQuery.ajax({
		type: "POST",
		async : false,
		url: "ajaxChargeCases.php",
		data: 'cli_code='+cli_code,
		success: function(result){
			if ( result == -1 ){
				coolMessage("error", "An error ocurred loading the cases.");
			}
			else{
				if( result == 0)
					coolMessage("information", "The client does not have cases.")
				else{
					document.getElementById("content_clients").innerHTML = result;
				}
			}
		}
		});
		return false;
	}
	
	function chargeBankContact(ban_code){
		if ( ban_code == -1 )//document.getElementById("link_bank").click();			
			$("#link_bank").trigger('click');
		else{
			jQuery.ajax({
			type: "POST",
			async : false,
			url: "ajaxChargeBankContact.php",
			data: 'ban_code='+ban_code,
			success: function(result){
				if ( result == -1 ){
					coolMessage("error", "An error ocurred loading the bank's contacts.");
				}
				else{
					if( result == 0)
						coolMessage("information", "The bank does not have contacts.")
					else{
						document.getElementById("content_bankContacts").innerHTML = result;
					}
				}
			}
			});
		}
		return false;
	}
	
	function checkContactBank(baco_code){
		if ( baco_code == -1 ){
			var ban_code = document.getElementById("ban_code").value;
			document.getElementById("link_bank_contact").setAttribute('href', 'addBankContact.php?ban_code='+ban_code);
			$("#link_bank_contact").trigger('click');
		}
		return false;
	}
	
	function onlyNumbers(e){
		var key;
		if(window.event)
			key = window.event.keyCode;   //IE
		else
			key = e.which;                //firefox
		if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 ))
			return false;
		else
			return true;
	}
	
	function reloadBanks(html_banks){
		document.getElementById("content_banks").innerHTML = html_banks;
		document.getElementById("content_bankContacts").innerHTML = '<select name="baco_code" id="baco_code" class="text_grv" onchange="javascript: checkContactBank(this.value);"><option value="" selected="selected" disabled="disabled">Select..</option><option value="-1">New contact bank..</option></select>';
		$.fn.fancybox.close();
	}
	
	function reloadContactsBank(html_contactsbank){
		document.getElementById("content_bankContacts").innerHTML = html_contactsbank;
		$.fn.fancybox.close();
	}
	
	function showCoolMessage(msg, type){		
		if ( type == 1 ){
			$.fn.fancybox.close();
			coolMessage("error", msg);
		}
		return false;
	}
	
</script>
</head>
<body>
<?php $item_select = 4; include("menu.php");?><br />
	<form name="form" id="form" method="post" action="" enctype="multipart/form-data">
	<input type="hidden" name="add" id="add" value="1"/>		
	<input type="hidden" name="req_code" id="req_code" value="<?php echo $req_code;?>"/>
    <div class="content_grv">
		<a href="addBank.php" class="fancyto" id="link_bank"></a>
	    <a href="addBankContact.php" class="fancytoContact" id="link_bank_contact"></a>
		<table width="90%" align="center" class="shadow">
            <tr>
                <td class="title">Request</td>
            </tr>
            <tr>
                <td>
                    <table class="tbl_form" align="center">                        
                        <tr>
                            <td align="right" width="35%"><span class="lbl_gray">Client:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td>
                            <?php if ($cli_code){?>
                                <span class="lbl_black"><?php echo $cli_name.' '.$cli_lastname;?></span>
                                <input type="hidden" name="cli_code" id="cli_code" value="<?php echo $cli_code;?>" />
                            <?php }else{?>
                            	<select name="cli_code" id="cli_code" class="text_grv" onchange="javascript: chargeCases(this.value);">
                                    <option value="" selected="selected" disabled="disabled">Select..</option>
                                    <?php 
									$countClient = count($listClients);
									for($i=0; $i < $countClient; $i++){?>
                                    <option value="<?php echo $listClients[$i]->cli_code;?>"><?php echo $listClients[$i]->cli_name." ".$listClients[$i]->cli_lastname;?></option>
                                    <?php }?>
								</select>
                            <?php }?>
                            </td>                            
                        </tr>
                        <?php if ( $use_code ){?>
                        <tr>
                            <td align="right"><span class="lbl_gray">Adviser:</span></td>
                            <td>&nbsp;</td>
                            <td>
                                <span class="lbl_black"><?php echo $use_name.' '.$use_lastname;?></span>
                            </td>                            
                        </tr>
                        <?php }?>
                        <tr>
                            <td align="right"><span class="lbl_gray">Case Number:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            <?php if ($case_code){?>
                                <span class="lbl_black"><?php echo $case_number;?></span>
                                <input type="hidden" name="case_code" id="case_code" value="<?php echo $case_code;?>" />
                            <?php }else{?>
                            	<div id="content_clients">
                                    <select name="case_code" id="case_code" class="text_grv">
                                        <option value="" selected="selected" disabled="disabled">Select a client..</option>                                    
                                    </select>
                                </div>
                            <?php }?>
                            </td>
                            
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Bank:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            <div id="content_banks">
                                <select name="ban_code" id="ban_code" class="text_grv" onchange="javascript: chargeBankContact(this.value);">
                                    <option value="" selected="selected" disabled="disabled">Select..</option>
                                    <?php 
                                    $countBankList = count ($bankList);
                                    for($i=0; $i < $countBankList; $i++) {
                                        if ( $bankList[$i]->ban_code == $ban_code )
                                            $selected = 'selected';
                                        else
                                            $selected = '';
                                    ?>
                                    <option value="<?php echo $bankList[$i]->ban_code;?>" <?php echo $selected;?>><?php echo $bankList[$i]->ban_name;?></option>
                                    <?php }?>
                                    <option value="-1">New Bank..</option>
                                </select>
                            </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Bank's Phone:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            	<div id="content_bankContacts">
                                    <?php if ( $ban_code ){?>
                                    <select name="baco_code" id="baco_code" class="text_grv" onchange="javascript: checkContactBank(this.value);">
                                        <option value="" selected="selected" disabled="disabled">Select..</option>
                                        <?php                                         
                                        for($i=0; $i < $countBankContactList; $i++) {
                                            if ( $bankContactList[$i]->baco_code == $baco_code )
                                                $selected = 'selected';
                                            else
                                                $selected = '';
                                        ?>
                                        <option value="<?php echo $bankContactList[$i]->baco_code;?>" <?php echo $selected;?>><?php echo $bankContactList[$i]->baco_name;?></option>
                                        <option value="-1">New contact bank..</option>
                                        <?php }?>
                                    </select>
                                    <?php }else{?>
                                    <select name="baco_code" id="baco_code" class="text_grv" onchange="javascript: checkContactBank(this.value);">
                                        <option value="" selected="selected" disabled="disabled">Select a bank..</option>
                                    </select>
                                    <?php }?>
								</div>
                            </td>
                        </tr>
                        <tr>
                           <td align="right"><span class="lbl_gray">Loan Number:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="text" name="loan_number" id="loan_number" size="31" maxlength="30" class="text_grv" value="<?php echo  $dataRequest->loan_number; ?>" />
                            </td>
                        </tr>                        
						<tr><td colspan="3" align="center">&nbsp;</td></tr>
                        <tr>
                            <td colspan="3" align="center">
                                <input type="button" class="button_grv" value="Save" onclick="javascript: return validate();" />
                                <input type="reset" value="Reset" class="button_grv_cancel"/>
                                <input type="button" class="button_grv_cancel" value="Cancel" onClick="javascript:window.location.href='listRequest.php'" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>    
</body>
</html>
<?php include('divscoolmessage.php');?>